package cn.fay.chapter10;

public class Test16 {
	
	public static void ride(CycleFactory factory){
		Cycle c=factory.getCycle();
		c.ride();
	}
	public static void main(String[] args) {
		ride(Unicycle.factory);
		ride(Bicycle.factory);
		ride(Tricycle.factory);
	}
}
interface Cycle{
	void ride();
}
interface CycleFactory{
	Cycle getCycle();
}
class Unicycle implements Cycle{
	private Unicycle(){}
	private static int wheel=1;
	@Override
	public void ride() {
		System.out.println("I ride a unicycle,it has "+wheel+" wheel.");
	}
	public static CycleFactory factory=new CycleFactory() {
		@Override
		public Cycle getCycle() {
			return new Unicycle();
		}
	};
}
class Bicycle implements Cycle{
	private Bicycle(){}
	private static int wheel=2;
	@Override
	public void ride() {
		System.out.println("I ride a bicycle,it has "+wheel+" wheels.");
	}
	public static CycleFactory factory=new CycleFactory() {
		@Override
		public Cycle getCycle() {
			return new Bicycle();
		}
	};
}
class Tricycle implements Cycle{
	private Tricycle(){}
	private static int wheel=3;
	@Override
	public void ride() {
		System.out.println("I ride a tricycle,it has "+wheel+" wheels.");
	}
	public static CycleFactory factory=new CycleFactory() {
		@Override
		public Cycle getCycle() {
			return new Tricycle();
		}
	};
}